
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter/cupertino.dart';
import '../../utils/Settings.dart';
import 'LCellListLogic.dart';
import 'LCellListState.dart';

class LCellListPage extends StatelessWidget {

  const LCellListPage({super.key, required this.tag});
  final String tag;


  @override
  Widget build(BuildContext context) {

    LCellListLogic lCellListLogic = Get.find<LCellListLogic>(tag: tag);
    //这里的TAG一定要赋值给state，因为后面的查询框需要
    final LCellListState state = Get.find<LCellListLogic>(tag: tag).state;
    state.tag = tag;

    return Scaffold(
        // resizeToAvoidBottomInset: false,
        backgroundColor: Settings.backgroundColor,
        body:GetBuilder<LCellListLogic>(
          // assignId:true,
          // autoRemove:true,
          tag: tag,
          builder: (logic){
            return state.list.isEmpty&&state.isAutoLoad==true?logic.createMoreWidget():RefreshIndicator(
              //圆圈进度颜色
              color: Settings.primaryColor,
              //下拉停止的距离
              displacement: state.distance,
              //背景颜色
              backgroundColor: Colors.grey[200],
              onRefresh:()async{
                logic.onRefresh();
              },
              child: ListView.builder(
                physics: const AlwaysScrollableScrollPhysics(),//解决数据量少无法下拉刷新的问题，此参数表示保持listview任何情况都能滚动
                controller: state.scrollController,
                itemCount: state.list.length,
                itemBuilder: (context,index){
                  Widget tip = const Text("");
                  if(index == state.list.length-1){
                    tip = logic.createMoreWidget();
                  }

                  return Column(
                    children: [
                      state.buildItemWidget(state.list[index]),
                      // const Divider(),
                      Visibility(
                        visible: index == state.list.length-1,
                        child: tip,
                      )
                    ],
                  );
                },
              ),

            );
          },
        ),
        floatingActionButton:state.queryFormAttributes.isNotEmpty? FloatingActionButton(
          heroTag: state.tag,
          backgroundColor:Settings.primaryColor,
          child: const Icon(Icons.search,color: Colors.white,),
          onPressed: ()async{
            lCellListLogic.showCustomModalBottomSheet(context);
          },
        ):const Visibility(visible: false,child: Text(""),)
    );
  }

}